import personBank from "../others/sign_shopV2/component/person_bank.vue";
import { Toast } from "vant";

export default {
  data() {
    return {
      showPersonBank: false,
      show1: false,
      cardData: {},
      cardMessage: {},
      area_name: "",
      role_name: {}
    };
  },
  activated() {
    this.show1 = false;
    this.area_name = "";
    this.getCardDate();
    window.scrollTo(0, 0);
  },
  methods: {
    gotoBusiness() {
      this.$router.push(this.fun.getUrl("BusinessCard", {}, { mark_id: this.cardMessage.id, mark: "card" }));
    },
    gotoMember() {
      if (window.history.length <= 1) {
        this.$router.push(this.fun.getUrl("member"));
      } else {
        this.$router.go(-1);
      }
    },
    getCardDate() {
      $http
        .get(
          "plugin.business-card.frontend.controllers.center.card.index",
          {},
          " "
        )
        .then(
          response => {
            if (response.result === 1) {
              this.cardData = response.data;
              this.cardMessage = this.cardData.has_one_card;
              this.role_name = this.cardData.role_name;
              
              this.cardData.area_name.forEach((item,index) => {
                if(item == null) {
                  this.cardData.area_name[index] = ''
                }
              })
              if (this.cardData.banner) {
                this.bacImage = { backgroundImage: "url(" + this.cardData.banner + ")" };
              }
              if (this.cardData.is_street === "1") {
                this.area_name =
                  this.cardData.area_name[0] +
                  this.cardData.area_name[1] +
                  this.cardData.area_name[2] +
                  (this.cardData.area_name[3] || '') +
                  this.cardData.has_one_card.address;
              } else {
                this.area_name =
                  this.cardData.area_name[0] +
                  this.cardData.area_name[1] +
                  this.cardData.area_name[2] +
                  this.cardData.has_one_card.address;
              }

            } else {
              this.$router.push(this.fun.getUrl("home"));
              Toast(response.msg);
            }
          },
          function(response) {
            console.log(response);
          }
        )
        .catch(error => {
          console.log(error);
        });
    },
    toPage(url) {
      console.log(url);
      this.$router.push(this.fun.getUrl(url, { card_id: this.cardMessage.id }));
    },
    toSignIndexV2(status){
      if(status) {
        this.showPersonBank = true;
      }
    }
  },
  components: { personBank }
};
